
var app=angular.module("huabote",['ui.router','ngSanitize','ui.bootstrap']);
app.config(function($stateProvider,$urlRouterProvider){
    $urlRouterProvider.when("","/home")
	$stateProvider.state("home",{
		url:"/home",
		templateUrl:"/views/home/index.html",
		controller:"home",
	})
	$stateProvider.state("about",{
		url:"/about/:paramId/:page",
		templateUrl:"/views/aboutUs/index.html",
		controller:"about",
	})
	$stateProvider.state("news",{
		url:"/news/:paramId/:page",
		templateUrl:"/views/news/index.html",
		controller:"about",
	})
	$stateProvider.state("connect",{
		url:"/connect/:paramId/:page",
		templateUrl:"/views/connectUs/index.html",
		controller:"connect",
	})
	$stateProvider.state("business",{
		url:"/business/:paramId/:page",
		templateUrl:"/views/business/index.html",
		controller:"business",
	})
	$stateProvider.state("schoolDetail",{
		url:"/schoolDetail/:schoolId",
		templateUrl:"/views/business/schoolDetail.html",
		controller:"schoolDetail",
	})
	$stateProvider.state("majorDetail",{
		url:"/majorDetail/:majorId",
		templateUrl:"/views/business/majorDetail.html",
		controller:"majorDetail",
	})
	$stateProvider.state("notice",{
		url:"/notice/:paramId/:page",
		templateUrl:"/views/news/index.html",
		controller:"notice",
	})
	$stateProvider.state("student",{
		url:"/student/:paramId/:page",
		templateUrl:"/views/student/index.html",
		controller:"student",
	})
	$stateProvider.state("detail",{
		url:"/detail/:paramId/:contentId",
		templateUrl:"/views/detail/index.html",
		controller:"detail",
	})
	$stateProvider.state("enroll",{
		url:"/enroll/:paramId/:page",
		templateUrl:"/views/enroll/index.html",
		controller:"enroll",
	})
	$stateProvider.state("school",{
		url:"/school/:paramId/:page",
		templateUrl:"/views/business/index.html",
		controller:"business",
	})
})
app.run(function($rootScope,$state){
	$rootScope.$on("toRoot",function(evt,data){
		$rootScope.menusData=data;
	})
	$rootScope.$on("$stateChangeSuccess",function(evt,toState,fromState,fromParams){
		$rootScope.stateName=toState.name;
		$rootScope.currentMenusData=[];
	
		$rootScope.$watch("menusData",function(data){
			if(data){
				angular.forEach(data,function(data){
					if(data.url==$rootScope.stateName){
						$rootScope.currentMenusData.push(data);
						// $rootScope.title=data.name;
						// console.log($rootScope.title);
					
					}
					if(data.url=="home"||$state.params.paramId==data.id){
						$rootScope.keyword=data.keyword;
						$rootScope.discription=data.discription;
						console.log($rootScope.keyword)
					}
					if(data.url=="home"||data.id==$state.params.paramId){
						$rootScope.title=data.name;
						console.log($rootScope.title);
					}
					
					if(data.eName=='groupIntroduce'){
						$rootScope.intrId=data.id;
					}
					if(data.eName=='school'){
						$rootScope.majorTypeId=data.id;
						console.log($rootScope.majorTypeId)
					}
				})
				console.log($rootScope.currentMenusData);
			}
		})
		//分页导航条设置
		$rootScope.maxSize=5; 
	})
})

